package com.zhi.controller;

import com.zhi.entity.HealthInfo;
import com.zhi.entity.LDCode;
import com.zhi.entity.User;
import com.zhi.service.LDCodeService;
import com.zhi.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class FoodPreController {
    @Autowired
    private LDCodeService ldCodeService;
    @RequestMapping("/toFoodPre")
    public String toFoodPre(Model model, HttpSession session){
        //获取当前登录用户
//        User sessionUser = (User)session.getAttribute("sessionUser");
//        int userId = (Integer)sessionUser.getId();
        //查询食物类别
        List<LDCode> foodA = ldCodeService.findByCodeType("foodA");
        List<LDCode> foodB = ldCodeService.findByCodeType("foodB");
        List<LDCode> foodC = ldCodeService.findByCodeType("foodC");
        List<LDCode> foodD = ldCodeService.findByCodeType("foodD");
        List<LDCode> foodE = ldCodeService.findByCodeType("foodE");

        model.addAttribute("foodAs",foodA);
        model.addAttribute("foodBs",foodB);
        model.addAttribute("foodCs",foodC);
        model.addAttribute("foodDs",foodD);
        model.addAttribute("foodEs",foodE);
        return "student/food";
    }
    /**
     * 增加记录
     * @param
     * @return
     */
    @RequestMapping("/foodpre/save")
    @ResponseBody
    public R add(HttpServletRequest request, HttpSession session) {
        User sessionUser =(User)session.getAttribute("sessionUser");
        int userId = (Integer)sessionUser.getId();
        String s = request.getParameter("selected_display");

        return R.ok();
    }
}
